# coding: utf-8
from __future__ import absolute_import
from urllib.parse import quote
from celery.schedules import crontab
from app.config import server_config

# broker 配置 使用redis作为消息中间件
PASSWORD = quote(server_config.get('redis_password'))
BROKER_REDIS_URL = server_config.get('redis_url') + '13'
BROKER_URL = BROKER_REDIS_URL.format(PASSWORD)

CELERY_IMPORTS = ('app.cron.tasks')
# broker_pool_limit = 0
BROKER_POOL_LIMIT = 0
# BACKEND配置，使用redis
CELERY_REDIS_URL = server_config.get('redis_url') + '14'
CELERY_RESULT_BACKEND = CELERY_REDIS_URL.format(PASSWORD)

CELERY_TIMEZONE = 'Asia/Shanghai'
timezone = 'Asia/Shanghai'
USE_TZ = False
CELERY_ENABLE_UTC = False
DJANGO_CELERY_BEAT_TZ_AWARE = False
CELERY_ACCEPT_CONTENT = ['json']
# accept_content = ['json']
CELERY_TASK_SERIALIZER = 'json'
# task_serializer = 'json'
CELERY_RESULT_SERIALIZER = 'json'
# result_serializer = 'json'
# 每个worker最多执行6个任务被销毁，可以防止内存泄漏
CELERYD_MAX_TASKS_PER_CHILD = 6
# worker_max_tasks_per_child = 6

CELERYBEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler'
# beat_schedule = 'django_celery_beat.schedulers.DatabaseScheduler'

# 定时任务
# CELERYBEAT_SCHEDULE = {
#     'sync_cmdb': {
#         "task": "app.cron.sync_cmdb.sync_cmdb",
#         "schedule": crontab(minute="*/35"),
#     },
# 'sync_processing_order_by_every': {
#     "task": "app.cron.tasks.sync_processing_order",
#     "schedule": crontab(minute="*/35"),
# },
# 'sync_processing_order_by_date': {
#     "task": "app.cron.tasks.sync_processing_order",
#     "schedule": crontab(minute=40, hour=19),   # 每晚23:30
# },
# 'sync_current_order_by_every': {
#     "task": "app.cron.tasks.sync_current_order",
#     "schedule": crontab(minute="*/10"),   # every minute 每分钟执行
# },
# 'sync_current_order_by_date': {
#     "task": "app.cron.tasks.sync_current_order",
#     "schedule": crontab(minute=10, hour=23),   # 每晚23:10
# },
# 'get_remain_order_count': {
#     "task": "app.cron.tasks.get_remain_order_count",
#     # "schedule": crontab(minute=0, hour=6, day_of_week=1),
#     "schedule": crontab(minute=50, hour=19),   # 每晚19:50
#     # "args": (90, 0),  # 参数
# },
# }
